package com.gdwstudy.drew;

import javax.swing.*;
import java.awt.*;

/**
 * @author 关道伟
 * @version 1.0
 */
@SuppressWarnings({"all"})
public class DrewCircle extends JFrame {
    private MyPanel mp = null;
    public static void main(String[] args) {
        new DrewCircle();
    }

    public DrewCircle(){
        mp = new MyPanel();
        this.add(mp);
        this.setSize(400,300);
        //点击窗口的小叉就结束进程
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        this.setVisible(true);
    }
}

//1.先定义一个MyPanel，继承JPanel类 画图类 就在画板上画
class MyPanel extends JPanel {
    @Override
    public void paint(Graphics g) {
        //System.out.println("paint放法被调用");
        super.paint(g);
        //画圆
        g.drawOval(10,10,100,100);


        //演示绘制不同的图形
        g.drawLine(10,10,100,100);
        g.drawRect(10,10,100,100);
        g.setColor(Color.BLUE);
        g.fillRect(20,20,80,80);

        Image image = Toolkit.getDefaultToolkit().getImage(Panel.class.getResource("/flower.jpg"));
        g.drawImage(image,10,10,300,224,this);


    }
}
